package com.gitee.wsl.ext.collection

import com.gitee.wsl.base.AnyIterable
import com.gitee.wsl.base.AnyMap


fun Sequence<Any?>.flatten(recursively: Boolean): Sequence<Any?> {
    return flatMap { element ->
            when (element) {
            is AnyMap -> sequenceOf(element)
            is AnyIterable -> element.asSequence().let {
                if (recursively) {
                    it.flatten(recursively = true)
                } else {
                    it
                }
            }
            else -> sequenceOf(element)
        }
    }
}